$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + '/merchant/orderList',
        datatype: "json",
        colModel: [         
        { label: 'ID', name: 'id', width: 30, key: true },
        { label: '申请人', name: 'proposer', width: 60 },
        { label: '商品名称', name: 'name', width: 100 },
        { label: '平台账号', name: 'platformAccount', width: 100 },
        { label: '订单号', name: 'orderNum', width: 100 },
        {
          label:"QQ",name:"qqId",width: 100 ,formatter: function(value, options, row){
                var rtn='--'
                if(value !=null && value !='null'){
                    var rtn='<a href="tencent://message/?uin='+value+'&Site=http://vps.shuidazhe.com&Menu=yes">'+value+'</a>' ;
                }
                return  rtn;
            }},
          {label:"状态",name:"status",width: 100,formatter: function(value, options, row){
            return '待确认订单号' ;
        }},
        { label: '操作', name: 'status', width: 80, formatter: function(value, options, row){
            return '<span class="btn btn-info" onclick="pass('+row.id+','+row.trailId+')">确认订单</span>&nbsp;<span class="btn btn-danger"  onclick="showRefuse('+row.trailId+','+row.id+')">拒绝</span>&nbsp;<span class="btn btn-primary" onclick="chat('+row.id+','+row.trailId+')">聊天</span>';
        }},
        ],
        viewrecords: true,
        height: 515,
        rowNum: 10,
        rowList : [10,30,50],
        rownumbers: true,
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "data.data",
            page: "data.pageNo",
            records: "data.totalNum"
        },
        prmNames : {
            page:"pageNo", 
            rows:"pageSize", 
            order: "order"
        },
        gridComplete:function(){
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});
function pass(id,trailId){
    confirm("您确定订单填写正确吗？",function () {
        var data={"id":id,"trailId":trailId};
        $.ajax({
            type: "POST",
            url: baseURL + "/merchant/aduitOrderNum",
            dataType: "json",
            contentType:"application/json",
            data:JSON.stringify(data),
            success: function(r){
                if (r.code===0) {
                    top.location.reload();
                    // var page = $("#jqGrid").jqGrid('getGridParam','page');
                    // $("#jqGrid").jqGrid('setGridParam',{
                    //     postData:{'key': vm.q.key},
                    //     page:page
                    // }).trigger("reloadGrid");
                }else{
                    alert(r.info);
                }

            }
        });
    })
};

function showRefuse(rId,aId) {
    debugger;
    vm.refuseObj.trailId =rId;
    vm.refuseObj.id =aId;
    $("#showModel").click();
}

function chat(id,trailId){
    vm.refuseObj.id=id;
    vm.refuseObj.trailId=trailId;
    $("#chatModel").click();
};

var vm = new Vue({
    el:'#rrapp',
    data:{
        q:{
            key: null
        },
        showList: true,
        title: null,
        refuseObj:{
            comments:null,
            trailId:null,
            id:null
        }

    },
    methods: {
        query: function () {
            vm.reload();
        },
        reload: function () {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam','page');
            $("#jqGrid").jqGrid('setGridParam',{ 
                postData:{'key': vm.q.key},
                page:page
            }).trigger("reloadGrid");
        },
        subRefuse:function () {
            if(null ==$.trim(this.refuseObj.comments) || ''==$.trim(this.refuseObj.comments) ){
                layer.alert("理由不可以为空哦！");
            }else{
                var data=this.refuseObj;
                $.ajax({
                    type: "POST",
                    url: baseURL + "/merchant/refuseAduit",
                    dataType: "json",
                    contentType:"application/json",
                    data:JSON.stringify(data),
                    success: function(r){
                        if (r.code===0) {
                            $("#close").click();
                            var page = $("#jqGrid").jqGrid('getGridParam','page');
                            $("#jqGrid").jqGrid('setGridParam',{
                                postData:{'key': vm.q.key},
                                page:page
                            }).trigger("reloadGrid");
                            alert(r.info);
                        }else{
                            alert(r.info);
                        }

                    }
                });
            }
        },

        chatSend:function () {

        }
    }
});